<template>
  <q-page class="q-pa-md">
    <div class="row items-center">
      <div class="q-pb-md text-h5">
        {{ pageTitle }}
        <span class="text-subtitle1">列表</span>
      </div>
      <q-space></q-space>
      <search-bar-toggle-btn v-model="searchBarVisibility"></search-bar-toggle-btn>
    </div>
    <!-- 查询菜单 -->
    <div class="q-pa-sm shadow-2 q-mb-md items-center" v-show="searchBarVisibility">
      <div class="row q-col-gutter-sm">
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">工序名称</div>
          <div class="col-8">
            <q-input :hide-bottom-space="true" @focus="fx.ui.select" @keyup.enter="loadListData(2)" dense
              :maxlength="40" outlined square stack-label v-model="fpsReq.serialName" :readonly="listDataLoadingState"
              clearable>
            </q-input>
          </div>
        </div>
        <div class="q-mr-sm">
          <q-btn :disable="listDataLoadingState" @click="loadListData(2)" color="primary" icon="search" label="查询" />
        </div>
      </div>
    </div>
    <div class="shadow-2">
      <q-table @request="fpsAssist.onDataTableRequest" :rows="$d.tableData" :columns="fpsInfo.columnsInfo"
        separator="cell" row-key="id" v-model:pagination="fpsInfo.paginationInfo"
        :visible-columns="fpsInfo.visibleColumns" dense flat :hide-pagination="true" :loading="listDataLoadingState"
        color="primary" binary-state-sort @row-dblclick="(evt,row)=>{fpsNav.gotoDetail(row.id)}">
        <template v-slot:top="props">
          <!--功能按钮-->
          <div class="q-gutter-sm">
          </div>
          <!--填充所有剩余空间-->
          <q-space />
          <table-col-options-cfg v-model:visible-columns="fpsInfo.visibleColumns"
            v-model:table-columns="fpsInfo.columnsInfo" class="q-mx-sm"
            @update-col-options-for-save="fpsAssist.saveColOptions"></table-col-options-cfg>
          <q-btn :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'" :ripple="false"
            :title="props.inFullscreen ? '退出全屏' : '全屏显示'" dense flat @click="props.toggleFullscreen" />
        </template>
        <template v-slot:no-data>
          <div class="full-width items-center justify-center row">
            <q-icon name="error_outline" />
            无数据
            <q-btn :disable="listDataLoadingState" :loading="listDataLoadingState" class="q-ml-sm" dense
              flat icon="refresh" size="sm" title="刷新" @click="loadListData"></q-btn>
          </div>
        </template>
        <template v-slot:bottom>
          <paging-bar :loading-state="listDataLoadingState" :pageNo="fpsReq.pageNo" :pageSize="fpsReq.pageSize"
            :totalAmount="fpsInfo.totalAmount" @pagesize-changed="fpsAssist.onPageSizeChanged"
            @go-to-page="fpsNav.gotoPage" />
        </template>
        <template v-slot:body-cell-operation="props">
          <q-td :props="props" auto-width>
            <q-btn class="btn-in-row" color="primary" dense label="查看"
                @click="evt=> fpsNav.gotoDetail(props.row.id, evt)" />
          </q-td>
        </template>
      </q-table>
    </div>
  </q-page>
</template>

<script lang="ts">
export default {
  name: 'LabelManagementListStd'
}
</script>
<script lang="ts" setup>
import {useTitleHelper} from '@njt/foundation/hooks/titleHelper'
import {reactive, ref} from 'vue'
import {ColumnInfo} from '@njt/foundation/defs/comm'
import {useFpsHelper} from '@njt/foundation/hooks/fpsHelper'
import {
  GetLabelBasicProcessListReq, GetLabelBasicProcessListResp, MhlbcLabelBasicProcess,

} from 'src/defs/labelManagement'

const pageTitle = '贴标工序管理'
useTitleHelper(pageTitle)

// 是否处于数据列表加载的状态
let listDataLoadingState = ref(false)

// 列参数
const columnsDefine: ColumnInfo[] = [
  {
    label: '操作',
    name: 'operation',
    field: 'operation',
    align: 'left',
    defOrder: 0,
    defVisible: true
  },
  {
    label: '工序ID',
    name: 'id',
    field: 'id',
    align: 'left',
    defOrder: 2,
    sortable: true,
    defVisible: true
  },
  {
    label: '工序编号',
    name: 'serialNumber',
    field: 'serialNumber',
    align: 'left',
    defOrder: 3,
    defVisible: false
  },
  {
    label: '工序名称',
    name: 'serialName',
    field: 'serialName',
    align: 'left',
    defOrder: 4,
    sortable: true,
    defVisible: true
  },
  {
    label: '工序系数',
    name: 'serialCoefficient',
    field: 'serialCoefficient',
    align: 'left',
    defOrder: 5,
    sortable: true,
    defVisible: true
  },
  {
    label: '创建人',
    name: 'createP',
    field: 'createP',
    align: 'left',
    defVisible: true,
    defOrder: 11,
    format: (val: string,row: any) => $f.fmt.userDisp(val, row.createPn)
  },
  {
    label: '创建时间',
    name: 'createDt',
    field: 'createDt',
    align: 'left',
    defVisible: true,
    defOrder: 12,
    format: (val: string) => $f.fmt.dtFmtFullNoSec(val)
  },
  {
    label: '更新时间',
    name: 'updateDt',
    field: 'updateDt',
    align: 'left',
    defOrder: 13,
    sortable: false,
    defVisible: true,
    format: (val: string) => $f.fmt.dtFmtFullNoSec(val)
  },
  {
    label: '更新人',
    name: 'updateP',
    field: 'updateP',
    align: 'left',
    defOrder: 14,
    sortable: false,
    defVisible: true,
    format: (val: string, row: any) => $f.fmt.userDisp(val, row.updatePn)
  }
]

let fpsReq: GetLabelBasicProcessListReq = reactive({
  serialName: null,
  pageNo: 1,
  pageSize: 40,
  isDescending: false,
  orderBy: null
})

let $d = reactive({
  tableData: [] as MhlbcLabelBasicProcess[]
})

const loadListData = function (resetFpsReq?: number) {
  if (resetFpsReq) {
    if (resetFpsReq >= 1) {
      fpsReq.pageNo = 1
    }
    if (resetFpsReq >= 2) {
      fpsReq.orderBy = ''
      fpsReq.isDescending = false
    }
  }
  listDataLoadingState.value = true
  $f.axios.get<GetLabelBasicProcessListResp>('/project/mhlbc/inv/inventory/get-label-basic-process-list', {params: fpsReq})
    .then((result) => {
      fpsAssist.handleGenericFpsResp(result.data)
      $d.tableData = result.data.mhlbcLabelBasicProcesses
      fpsAssist.saveFpsReq(fpsReq)
    })
    .catch((err) => {
      $f.ui.showNotifyFailed($f.getAxiosErrMsg(err))
    })
    .finally(() => {
      listDataLoadingState.value = false
    })
}

const {
  fpsInfo,
  fpsAssist,
  fpsNav,
  searchBarVisibility
} = useFpsHelper('/wms/sku/label-management',
  '/wms/sku/label-management/detail',
  '',
  '',
  fpsReq, columnsDefine,
  null,
  loadListData)

const fx = $f
</script>
